<?php

namespace App\Console\Commands\Shop;

use App\Imports\Shop\ShopAttributeGoodsNameImport;
use GuzzleHttp\Client;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;
use Maatwebsite\Excel\Facades\Excel;

class InitShopAttributeByKfosGoodsName extends Command
{
    protected $signature = 'shop:initShopAttributeByKfosGoodsName';

    protected $description = '初始化门店属性-售卖品类 通过订货匹配 炸鸡 主食 包装饮品 景区精选';

    public function handle()
    {

        $url                                   = $this->ask('请输入excel地址 : ',
            'https://file.51kuafu.com/ec/f6/767e262abce0a0d0d656a380de906da02505cfcd773453c3ef1804fa0a8a.csv');
        ShopAttributeGoodsNameImport::$command = $this;
        $pathInfo                              = parse_url($url);
        $client                                = new Client();
        $tempData                              = $client->request('get', $url)->getBody()->getContents();
        $file                                  = md5($url) . date('YmdHis', time()) . '.' . implode('.', $pathInfo)[1];
        Storage::disk('public')->put($file, $tempData);
        Excel::import(new ShopAttributeGoodsNameImport(), storage_path('app/public') . "/{$file}");
        Storage::disk('public')->delete($file);
        return 0;
    }
}


